package com.itheima.ball;

import com.itheima.util.BallUtil;

import java.util.*;

public class Test01 {

    public static void main(String[] args) {
        TreeSet<Integer[]> list=new TreeSet<>(
                (arr1,arr2)->{
                   int i1= arr1[0]-arr2[0];
                   int i2=i1==0?arr1[1]-arr2[1]:i1;
                   int i3=i2==0?arr1[2]-arr2[2]:i2;
                   int i4=i3==0?arr1[3]-arr2[3]:i3;
                   int i5=i4==0?arr1[4]-arr2[4]:i4;
                   int i6=i5==0?arr1[5]-arr2[5]:i5;
                   int i7=i6==0?arr1[6]-arr2[6]:i6;
                    return i7;
                }
        );
       while (list.size()<5000){
            Integer[] balls = new BallUtil().getAllBalls();
            list.add(balls);
        }

      /*  for (Integer[] balls : list) {
            System.out.println(Arrays.toString(balls));
        }
*/
        //统计 10
        int count10=0;
        //统计 20
        int count20=0;
        //统计 30
        int count30=0;

        Map<Integer,Integer> map= new TreeMap<>();
        for (Integer[] balls : list) {
            for (Integer ball : balls) {
                if(ball==10){
                    count10++;
                }
                if(ball==20){
                    count20++;
                }
                if(ball==30){
                    count30++;
                }
                boolean flag = map.containsKey(ball);
                if(!flag){
                    map.put(ball,1);
                }else {
                    map.put(ball,map.get(ball)+1);
                }

            }
        }
        System.out.println("10出现的次数"+count10);
        System.out.println("20出现的次数"+count20);
        System.out.println("30出现的次数"+count30);
        ArrayList<String> list1 = new ArrayList<>();

        int max=0;
        map.forEach((k,v)->{
            System.out.println(k+"出现了"+v+"次");
            list1.add(k+"="+v);

        });

        int ball=0;
        for (int i = 0; i < list1.size(); i++) {
            int count = Integer.parseInt(list1.get(i).split("=")[1]);
            if(count>max){
                max=count;
                ball=Integer.parseInt(list1.get(i).split("=")[0]);
            }

        }
        System.out.println(ball+"一共出现了"+max+"次");
    }
}
